﻿/*
* @Author： whg
* @Date : 2021-1-19
* @Desc : 
*/
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using XNodeEditor;
[XNodeEditor.NodeEditor.CustomNodeEditor(typeof(DialogueNode))]
public class DialogueEditor : NodeEditor
{
    private DialogueNode node;
    public override void OnBodyGUI()
    {
        serializedObject.Update();
        if (node == null) node = target as DialogueNode;

        NodeEditorGUILayout.PortField(target.GetInputPort("upLink"));
        EditorGUILayout.Space();
        NodeEditorGUILayout.PropertyField(serializedObject.FindProperty("dialogueType"));
        EditorGUIUtility.labelWidth = 115;
        switch (node.dialogueType)
        {
            case DialogueNode.DialogueType.StoryDialog:
                NodeEditorGUILayout.PropertyField(serializedObject.FindProperty("Dialog_target"));
                NodeEditorGUILayout.PropertyField(serializedObject.FindProperty("Dialog_id"));
                NodeEditorGUILayout.PropertyField(serializedObject.FindProperty("Dialog_scale"));
                NodeEditorGUILayout.PropertyField(serializedObject.FindProperty("Dialog_time"));
                NodeEditorGUILayout.PropertyField(serializedObject.FindProperty("Dialog_content"));
                if (node.Dialog_target == DialogueNode.DialogueTarget.MainRole && node.Dialog_id != "me")
                    node.Dialog_id = "me";
                else if (node.Dialog_target != DialogueNode.DialogueTarget.MainRole && node.Dialog_id == "me")
                    node.Dialog_id = "10000";
                break;
            case DialogueNode.DialogueType.StoryTalkBoard:
                NodeEditorGUILayout.PropertyField(serializedObject.FindProperty("Talk_wait"));
                NodeEditorGUILayout.PropertyField(serializedObject.FindProperty("Talk_target"));
                NodeEditorGUILayout.PropertyField(serializedObject.FindProperty("TalkBoard_ins_id"));
                NodeEditorGUILayout.PropertyField(serializedObject.FindProperty("TalkBoard_time"));
                NodeEditorGUILayout.PropertyField(serializedObject.FindProperty("TalkBoard_width"));
                
                NodeEditorGUILayout.PropertyField(serializedObject.FindProperty("TalkBoard_offset"));
                NodeEditorGUILayout.PropertyField(serializedObject.FindProperty("TalkBoard_animation"));
                NodeEditorGUILayout.PropertyField(serializedObject.FindProperty("TalkBoard_content"));
                NodeEditorGUILayout.PropertyField(serializedObject.FindProperty("TalkBoard_func"));
                break;
            case DialogueNode.DialogueType.BlackMaskText:
                NodeEditorGUILayout.PropertyField(serializedObject.FindProperty("IsBlack"));
                NodeEditorGUILayout.PropertyField(serializedObject.FindProperty("BlackMask_time"));
                if (node.IsBlack)
                {
                    NodeEditorGUILayout.PropertyField(serializedObject.FindProperty("fontSize"));
                    NodeEditorGUILayout.PropertyField(serializedObject.FindProperty("lineSpacing"));
                    NodeEditorGUILayout.PropertyField(serializedObject.FindProperty("BlackMask_content"));
                }
                break;
        }
        NodeEditorGUILayout.PortField(target.GetOutputPort("downLink"));
        serializedObject.ApplyModifiedProperties();
    }
    public override int GetWidth()
    {
        return 220;
    }
}
